﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using C4F.DevKit.WebServices;
using C4F.DevKit.WebServices.Datasets;

namespace C4F.DevKit.WebServicesDemo
{
    public partial class DeliciousControl : UserControl
    {
        public DeliciousControl()
        {
            InitializeComponent();
        }

        private void GoButton_Click(object sender, EventArgs e)
        {

            try
            {
                DeliciousService.UrlUserName = UserName.Text;
                DeliciousService.UrlPassword = Password.Text;
                DeliciousResults = DeliciousService.GetPost_DS();
                DeliciousGrid.DataSource = DeliciousResults.DeliciousPost;
            }
            catch (System.Net.WebException ex)
            {
                StreamReader streamReader = new StreamReader(ex.Response.GetResponseStream());
                string responseData = streamReader.ReadToEnd();
                streamReader.Close();
                MessageBox.Show(responseData);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }      
        }

        private void DeliciousGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewSelectedCellCollection Cells = DeliciousGrid.SelectedCells;
            if (Cells[0] is System.Windows.Forms.DataGridViewLinkCell)
            {
                DataGridViewLinkCell LinkCell = (DataGridViewLinkCell)Cells[0];
                DemoBrowser BrowserForm = new DemoBrowser((string)LinkCell.Value);
                BrowserForm.Show();
            }                
        }

      


    }
}
